package org.aplombh.java.study.dp;

import java.util.Arrays;

public class Factorial {
    public static void main(String[] args) {
        System.out.println(factorial(10));
        System.out.println(dpFactorial(10));
    }

    private static int[] f = new int[999];

    static {
        f[0] = 1;
    }

    private static int dpFactorial(int n) {
        if (f[n] == 0) {
            return f[n] = dpFactorial(n - 1) * n;
        }
        return f[n];
    }

    public static int factorial(int n) {
        if (n <= 0)
            return 1;
        return factorial(n - 1) * n;
    }
}
